/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jimu.longkong.web;

import com.jimu.longkong.db.domain.User;
import javax.servlet.http.HttpSession;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author mazhiqiang
 */
public class Web {
    public static String ROOT = "/JimuWeb/";
    
    
    static public HttpSession getSession() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
    }
    
    
    public static User loginedRenyuan() {
        HttpSession session = Web.getSession();
        User u = (User) session.getAttribute("renyuan");
        return u;
    }
    
    public static boolean logined() {
        HttpSession session = Web.getSession();
        User u = (User) session.getAttribute("renyuan");
        if (u != null) {
            return true;
        } else {
            return false;
        }
    }
    
    public static ModelAndView redirect(String url) {
        return new ModelAndView("redirect:" + url);
    }
    
    public static ModelAndView errpage(String title, String message) {
        return new ModelAndView("/error.html")
                .addObject("title", title)
                .addObject("message", message);
    }        
}
